//author:jxx
//此处是对表单的方法，组件，权限操作按钮等进行任意扩展(方法扩展可参照SellOrder.js)
import details from "../../views/mall/mebcouponDetails.vue";
import mebcouponZQ from "../../views/mall/mebcouponZQ.vue";
let extension = {
  components: {
    //动态扩充组件或组件路径
    //表单header、content、footer对应位置扩充的组件
    gridHeader: "", //{ template: "<div>扩展组xx件</div>" },
    gridBody: details,
    gridFooter: mebcouponZQ,
    //弹出框(修改、编辑、查看)header、content、footer对应位置扩充的组件
    modelHeader: "",
    modelBody: "",
    modelFooter: ""
  },
  buttons: {
    view: [
      {
        name: "新建",
        icon: "md-add",
        value: "XJ",
        class: "",
        type: "error",
        index: 1, //显示的位置
        onClick: function () {
          this.$refs.gridBody.model = true;
          this.$refs.gridBody.title = "优惠券模板--新增";
          this.$nextTick(() => {
            this.$refs.gridBody.$refs.editFormFields.resetFields();
            this.$refs.gridBody.GetVueDictionary();
            this.$refs.gridBody.$refs.myform.reset();
            this.$refs.gridBody.formFields1.coupon_cover = "";
            this.$refs.gridBody.cascaderValue = "";
            this.$refs.gridBody.editFormFields.applicability = "1";
          });
        }
      }
    ],
    box: [],
    detail: []
  }, //扩展的按钮
  methods: {
    //事件扩展
    onInit () {
      // 不显示多选框
      //;
      // 显示序号
      //;
      // 开启单选
      //;
      this.$store.getters.data().viewPageTest = this;
      let param = ["MakeCoupon_Status"];
      this.http.post("/api/Dictionary/GetVueDictionary", param).then(res => {
        if (this.$refs.gridFooter.formRules && this.$refs.gridFooter.formRules.length) {
          this.$refs.gridFooter.formRules.forEach(i => {
            i.forEach(j => {
              if (j.field == "status") {
                j.data = [];
                res[0].data.forEach(ii => {
                  let obj = {
                    key: ii.key,
                    value: ii.value
                  };
                  j.data.push(obj);
                });
              }
            });
          });
        }
        this.$refs.gridFooter.columns.forEach(i => {
          if (i.field == "status") {
            i.bind.data = [];
            res[0].data.forEach(ii => {
              let obj = {
                key: ii.key,
                value: ii.value
              };
              i.bind.data.push(obj);
            });
          }
        });
      });
      this.columns.push({
        title: "操作",
        fixed: "right",
        width: 150,
        render: (h, { row, column, index }) => {
          return [
            h(
              "a",
              {
                on: {
                  click: () => {
                    this.$refs.gridFooter.model = true;
                    this.$refs.gridFooter.editFormFields.coupon_code = row.code;
                    this.$refs.gridFooter.editFormOptions[0][0].hidden = true;
                  }
                }
              },
              "制券  "
            ),
            h(
              'a', {
              on: {
                click: () => {
                  this.$refs.gridFooter.model2 = true
                  this.$refs.gridFooter.openUHFA(row.type)
                  console.log(row, "row")
                  var rowObj = this.$refs.gridFooter.editFormFields1
                  this.$nextTick(() => {
                    this.$refs.gridFooter.GetVueDictionary();
                    rowObj.is_entry_accoun = String(row.is_entry_accoun)
                    rowObj.name = row.name
                    rowObj.type = row.type
                    rowObj.coupon_value = row.coupon_value
                    rowObj.note = row.note
                    rowObj.discountCode=row.discountCode
                    rowObj.discountRe= row.discountRefer
                    rowObj.discount_id=row.discount_id
                    rowObj.use_threshold = String(row.use_threshold)
                    rowObj.activity_mutex_type = String(row.activity_mutex_type)
                    rowObj.threshold_value = row.threshold_value
                    rowObj.regulation = row.regulation
                    rowObj.applicability = String(row.applicability)
                    rowObj.receive_way = String(row.receive_way)
                    rowObj.applicable_people = String(row.applicable_people)
                    rowObj.amount_condition = String(row.amount_condition)
                    rowObj.per_daylimit = row.per_daylimit
                    rowObj.per_limit = row.per_limit
                    rowObj.receiveTime1 = row.receive_starttime
                    rowObj.receiveTime2 = row.receive_endtime
                    rowObj.threshold_value = row.threshold_value
                    // console.log("row.coupon_cover",row.coupon_cover)
                    this.$refs.gridFooter.formFields1.coupon_cover = row.coupon_cover == "" ? "---" : row.coupon_cover
                    if (row.use_threshold == 1) {
                      this.$refs.gridFooter.thresholdValue = true
                    } else {
                      this.$refs.gridFooter.thresholdValue = false

                    }
                    // 指定商品、品类
                    let param1 = {
                      order: "desc",
                      page: 1,
                      rows: 30,
                      sort: "",
                      wheres: `[{\"name\":\"coupon_id\",\"value\":\"${row.code
                        }\",\"displayType\":\"like\"}]`
                    };
                    this.http.post("/api/MebCouponAtegoryReleation/getPageData", param1).then(res => {
                      this.$refs.gridFooter.PLProtyLIST = res.rows
                    })
                    // 指定商户
                    this.http.get("/api/SupplierNews/GetMebCouponById", { id: row.appointed_supplier }).then(res => {
                      this.$refs.gridFooter.PLProtyLIST = res.data
                    })
                    //  指定人群名称
                    let param2 = {
                      order: "desc",
                      page: 1,
                      rows: 30,
                      sort: "",
                      wheres: `[{\"name\":\"membertypeid\",\"value\":\"${row.appointed_member
                        }\",\"displayType\":\"like\"}]`
                    };

                    this.http.post("/api/MebType/getPageData", param2).then(res => {
                      // this.$refs.gridFooter.hylxList
                      console.log(res, "-----")

                    });

                  })
                  // let param = {
                  //   order: "desc",
                  //   page: 1,
                  //   rows: 30,
                  //   sort: "id",
                  //   wheres: `[{\"name\":\"coupon_code\",\"value\":\"${row.code}\",\"displayType\":\"like\"}]`,
                  // }
                  // this.http.post('/api/MebcouponMake/getPageData', param).then(res => {
                  //   this.$refs.gridFooter.tableData = res.rows
                  // })
                }
              }
            }, "  查看券模版"),
          ];
        }
      });
    },
    rowClick ({ row, column, event }) {
      //查询界面table点击行选中当前行
      this.$refs.table.$refs.table.toggleRowSelection(row);
      return true;
    },
    delBefore (ids, rows) {
      let p = {
        order: "desc",
        page: 1,
        rows: 10000,
        sort: "createtime",
        wheres: `[{\"name\":\"coupon_code\",\"value\":\"${rows[0].code
          }\",\"displayType\":\"text\"}]`
      };
      this.http.post("/api/MebcouponMake/getPageData", p).then(res => {
        if (res.rows.length != 0) {
          this.$Message.error("此优惠券模板下有优惠券，暂不支持删除");
        } else {
          this.http.post("/api/MebCoupon/del", [ids.toString()]).then(res => {
            this.refresh();
          });
        }
      });
    }
  }
};
export default extension;
